<?php
/**
 * receiver.php
 *
 * Author: Lomo
 * Date: 2018-06
 * Email: lomo@lomo.space
 * URL: http://lomo.space
 *
 * Description: 消息消费者(接收, 读取mq中的消息)
 *
 */

    require_once __DIR__ .'/vendor/autoload.php';

    use PhpAmqpLib\Connection\AMQPStreamConnection;

    // 创建连接
    $connection = New AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
    $channel = $connection->channel();


    // 第一种 消息消费方式: basic_get
    // 取消息
    $msg = $channel->basic_get('lomo1');
    print_r($msg->body);

    // 必须添加，否则消费后 消息未从mq清除
    // 当mq中所有Ready的消息被消费完后，再次尝试去读取就会警告⚠️.
    $channel->basic_ack($msg->delivery_info['delivery_tag']);
    $channel->close();
    $connection->close();


